package com.zte.claa.inficombo.csa.app.model.dev;

import java.io.Serializable;

import com.zte.claa.inficombo.csa.app.model.redis.ProjectDev;

public class DevBase implements Serializable {
	/**
	 * 用于设备的缓存，快速获取devtype，为数据解析提供支撑。
	 */
	private static final long serialVersionUID = 1L;
	
	// 终端分类：0-普通lora终端；1-传感终端（不带Lora模块）; 2-蓝牙标签；12-中移NB设备；13-电信NB设备；14-联通NB设备；
	public static final byte DEV_TPFLAG_LORA = ProjectDev.DEV_TPFLAG_LORA;
	public static final byte DEV_TPFLAG_SENSOR = ProjectDev.DEV_TPFLAG_SENSOR;
	public static final byte DEV_TPFLAG_NB_CMCC = ProjectDev.DEV_TPFLAG_NB_CMCC;
	public static final byte DEV_TPFLAG_NB_CTCC = ProjectDev.DEV_TPFLAG_NB_CTCC;
	public static final byte DEV_TPFLAG_NB_CUCC = ProjectDev.DEV_TPFLAG_NB_CUCC;
	
	public static final byte RUN_STATE_JOIN = ProjectDev.RUN_STATE_JOIN;
	public static final byte RUN_STATE_ONLINE = ProjectDev.RUN_STATE_ONLINE;
	public static final byte RUN_STATE_OFFLINE = ProjectDev.RUN_STATE_OFFLINE;
	public static final byte RUN_STATE_UNKNOWN = ProjectDev.RUN_STATE_UNKNOWN;	
	
	public static final byte NETTYPE_LORA = 0x00;
	public static final byte NETTYPE_GPRS = 0x01;
	
	private String devEui;
	private String devType;
	private String devName;
	private String appEui;
	private String projectId;
	// 传感设备的类别标识.
	private byte devflag = DEV_TPFLAG_LORA;
	// 设备运行状态.
	private byte runState = RUN_STATE_UNKNOWN;	
	// 扩展metedata数据，仅WEB-CSA之间用到.
	private String datajson;
	// 设备网络类型
	private int networktype = NETTYPE_LORA;
    /**
     * 设备安装点GPS纬度
     */
    private double gpslat = 0;

    /**
     * 设备安装点GPS经度
     */
    private double gpslng = 0;

    /**
     * 设备安装点海拔
     */
    private int gpsalt = 0;
	
    /**
     * 构建器
     */
	public DevBase(){
		
	}

	public int getNetworktype() {
		return networktype;
	}

	public void setNetworktype(int networktype) {
		this.networktype = networktype;
	}

	public String getDevEui() {
		return devEui;
	}

	public void setDevEui(String devEui) {
		this.devEui = devEui;
	}

	public String getDevType() {
		return devType;
	}

	public void setDevType(String devType) {
		this.devType = devType;
	}

	public String getDevName() {
		return devName;
	}

	public void setDevName(String devName) {
		this.devName = devName;
	}

	public String getAppEui() {
		return appEui;
	}

	public void setAppEui(String appEui) {
		this.appEui = appEui;
	}

	public String getProjectId() {
		return projectId;
	}

	public void setProjectId(String projectId) {
		this.projectId = projectId;
	}

	public String getDatajson() {
		return datajson;
	}

	public void setDatajson(String datajson) {
		this.datajson = datajson;
	}

	public byte getDevflag() {
		return devflag;
	}

	public void setDevflag(byte devflag) {
		this.devflag = devflag;
	}

	public byte getRunState() {
		return runState;
	}

	public void setRunState(byte runState) {
		this.runState = runState;
	}

	public boolean checkIsSensor(){
		return this.devflag == DEV_TPFLAG_SENSOR;
	}
	
	public boolean checkIsLoraDev(){
		return this.devflag == DEV_TPFLAG_LORA;
	}
	
	public boolean checkNBIotDev(){
		return (this.devflag == DEV_TPFLAG_NB_CMCC ||
				this.devflag == DEV_TPFLAG_NB_CTCC || 
				this.devflag == DEV_TPFLAG_NB_CUCC);
	}
	
	// 对于lora终端，直接返回deveui；如果是非lora传感器，返回归属dtu的deveui.
	public String parseDtuDevEui(){
		if(this.checkIsSensor()){
			return ProjectDev.parseSensorDtuEui(this.devEui);
		}
		return this.devEui;
	}
	
	// 对于lora终端，直接返回""；如果是非lora传感器，返回对应的sensorid.
	public String parseSensorId(){
		if(this.checkIsSensor()){
			return ProjectDev.parseSensorId(this.devEui);
		}
		return "";
	}
	
	public double getGpslat() {
		return gpslat;
	}

	public void setGpslat(double gpslat) {
		this.gpslat = gpslat;
	}

	public double getGpslng() {
		return gpslng;
	}

	public void setGpslng(double gpslng) {
		this.gpslng = gpslng;
	}

	public int getGpsalt() {
		return gpsalt;
	}

	public void setGpsalt(int gpsalt) {
		this.gpsalt = gpsalt;
	}

	public String toString(){
		return "EUI="+this.devEui+",Name="+this.devName+", devflag="+this.devflag;
	}
}
